<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>

        .ht{
            text-align: center;
            color: #000000;
        }
        .tab{
            width: 500px;
            border: 5px solid #000000;
            margin: 0px auto;
            border-radius: 5px;
        }
        .ltr td{
            border: 1px solid #000000;

        }
        .ipt{
            border: 0px;
            width: 50%;

        }
        .btn1{
            border: 2px solid #000000;
            border-radius: 4px;
            width:60px;
            background-color: #ffffff;

        }

        .msg {
            color: #000000;
        }

        .buttonContainer{
            text-align: center;
        }
    </style>

    <script>
        function checkUsername(){
            var usernameReg = /^[a-zA-Z0-9]{5,10}$/
            var usernameInput = document.getElementById("usernameInput")
            var username = usernameInput.value
            var usernameMsg = document.getElementById("usernameMsg")
            if(!usernameReg.test(username)){
                usernameMsg.innerText="格式有误"
                return false
            }
            usernameMsg.innerText="OK"
            return true
        }


        function checkUserPwd(){
            var userPwdReg = /^\d{6}$/
            var userPwdInput = document.getElementById("userPwdInput")
            var userPwd = userPwdInput.value
            var userPwdMsg = document.getElementById("userPwdMsg")
            if(!userPwdReg.test(userPwd)){
                userPwdMsg.innerText="格式有误"
                return false
            }
            userPwdMsg.innerText="OK"
            return true
        }


        function checkReUserPwd(){
            var userPwdReg = /^\d{6}$/
            // 再次输入的密码的格式
            var reUserPwdInput = document.getElementById("reUserPwdInput")
            var reUserPwd = reUserPwdInput.value
            var reUserPwdMsg = document.getElementById("reUserPwdMsg")
            if(!userPwdReg.test(reUserPwd)){
                reUserPwdMsg.innerText="格式有误"
                return false
            }
            // 获得上次密码,对比两次密码是否一致
            var userPwdInput = document.getElementById("userPwdInput")
            var userPwd = userPwdInput.value
            if(reUserPwd != userPwd){
                reUserPwdMsg.innerText="两次密码不一致"
                return false
            }
            reUserPwdMsg.innerText="OK"
            return true
        }


        function checkForm(){
            var flag1 = checkUsername()
            var flag2 = checkUserPwd()
            var flag3 = checkReUserPwd()

            return flag1 && flag2 && flag3
        }


    </script>



</head>
<body>
<h3 class="ht">修改用户数据</h3>
<form method="get" action="/users/updateUser" onsubmit="return checkForm()">
    <table class="tab" cellspacing="0px">

        <tr class="ltr">
            <td>用户名</td>
            <td>
                <input class="ipt" id="usernameInput" type="text" name="username" onblur="checkUsername()">
                <span id="usernameMsg" class="msg"></span>
            </td>
        </tr>
        <tr class="ltr">
            <td>是否为管理员(0否,1是)</td>
            <td>
                <input class="ipt" id="isAdminInput" type="text" name="isAdmin">
            </td>
        </tr>
        <tr class="ltr">
            <td>是否可用(0否,1是)</td>
            <td>
                <input class="ipt" id="availableInput" type="text" name="available">
            </td>
        </tr>
        <tr class="ltr">
            <td colspan="2" class="buttonContainer">
                <input class="btn1" type="submit" value="确认修改">
                <input class="btn1" type="reset" value="重置">
            </td>
        </tr>
    </table>
</form>
</body>
</html>